﻿using System;
using System.Collections.Generic;
using FluentNHibernate.Testing;
using NUnit.Framework;
using SinBiota.Model.Entities;

namespace SinBiota.UnitTests.NHibernate
{
    [TestFixture]
    class MappingFixture : FixtureBase
    {

        [Test]
        public void CanMapInstitution()
        {
            new PersistenceSpecification<Institution>(Session)
                .CheckProperty(u => u.Id, 1001)
                .CheckProperty(u => u.Name, "Universidade de Campinas")
                .VerifyTheMappings();
        }
        [Test]
        public void CanMapMunicipality()
        {
            new PersistenceSpecification<Municipality>(Session)
                .CheckProperty(u => u.Id, 2002)
                .CheckProperty(u => u.Name, "Campinas")
                .CheckReference(u => u.State, State.SP)
                .VerifyTheMappings();
        }
        [Test]
        public void CanMapProject()
        {

            new PersistenceSpecification<Project>(Session)
                .CheckProperty(c => c.Id, 1001)
                //.CheckProperty(c => c.Name, "Projeto Biota")
                //.CheckList(c => c.Coordinators, new List<Researcher>())
                //.CheckList(c => c.Members, new List<Researcher>())
                .VerifyTheMappings();
        }

        [Test]
        public void CanMapPublication()
        {
            var university1 = new Institution { Name = "Universidade de Campinas"};
            var university2 = new Institution { Name = "Universidade de São Paulo"};
            var researcher1 = new User { Username = "Pedro" };
            var researcher2 = new User { Username = "João"};
            var researcher3 = new User { Username = "Zé"};
            var researcher4 = new User { Username = "Mané"};

            var project = new Project { Name = "Biota" };
            //project.Coordinators.Add(researcher1);
            //project.Coordinators.Add(researcher2);
            //project.Members.Add(researcher3);
            //project.Members.Add(researcher4);

            new List<User> { researcher1, researcher4 };
            new PersistenceSpecification<Publication>(Session)
                .CheckProperty(p => p.Id, 4004)
                .CheckProperty(p => p.Title, "My Title")
                .CheckProperty(p => p.Journal, "My Journal")
                .CheckProperty(p => p.Number, "5 (6)")
//                .CheckList(p => p.Authors, new List<Author>())
                .VerifyTheMappings();
        }

        [Test]
        public void CanMapUser()
        {
            new PersistenceSpecification<User>(Session)
                .CheckProperty(c => c.Id, 1001)
                .CheckProperty(c => c.Email, "pedro@home")
                .CheckProperty(c => c.Password, "123456789012345678901234567890")
                .CheckProperty(c => c.PasswordSalt, Guid.NewGuid().ToString())
                .CheckProperty(c => c.Username, "pedro")
                .CheckProperty(c => c.Comment, null)
                .CheckProperty(c => c.PasswordQuestion, null)
                .CheckProperty(c => c.PasswordAnswer, null)
                .CheckProperty(c => c.IsApproved, true)
                .CheckProperty(c => c.IsLockedOut, false)
                .CheckProperty(c => c.IsOnline, false)
                .CheckProperty(c => c.CreationDate, DateTime.MinValue)
                .CheckProperty(c => c.LastLoginDate, DateTime.MinValue)
                .CheckProperty(c => c.LastActivityDate, DateTime.MinValue)
                .CheckProperty(c => c.LastLockedOutDate, DateTime.MinValue)
                .CheckProperty(c => c.LastPasswordChangedDate, DateTime.MinValue)
                .CheckProperty(c => c.Role, Role.Admin)
                .VerifyTheMappings();


        }


    }
}
